package smlab.astar
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.clearInterval;
	
	import smlab.utils.DisplayObjectUtil;
	
	public class Actor extends Sprite
	{
		private var _direction:String = Direction.DOWN;
		private var _pos:Point = new Point();
		private var _centerPoint:Point = new Point();
		private var _speed:Number = 5;
		private var _walk:IWalk;
		private var skin:Sprite;
		
		public function Actor()
		{
			skin=new Sprite;
			var w:Number=30;
			var h:Number=30;
			skin.graphics.beginFill(0);
			skin.graphics.drawRect(0,0,w,h);
			addChild(skin);
			skin.graphics.lineStyle(2,0xffffff);
			skin.graphics.moveTo(w/2,h/2);
			skin.graphics.lineTo(0,h/2);
			
			skin.x=-w/2;
			skin.y=-h/2;

			//默认地面走
			_walk = new WalkAction();
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(e:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			DepthManager.swapDepth(this, y);
		}
		
		/**
		 * 速度
		 * @param value
		 *
		 */
		public function set speed(value:Number):void
		{
			_speed = value;
		}
		
		public function get speed():Number
		{
			return _speed;
		}
		
		/**
		 * 获取动作 
		 * @return 
		 * 
		 */		
		public function get walk():IWalk
		{
			return _walk;
		}
		public function set walk(walk:IWalk):void
		{
			if(_walk)
			{
				_walk.destroy();
			}
			_walk = null;
			_walk = walk;
		}
		/**
		 * 播放动作
		 * 
		 */		
		public function play():void
		{
		}
		
		/**
		 * 停止动作 
		 * 
		 */		
		public function stop():void
		{
			_walk.stop();
		}
		
		/**
		 * 设置坐标点 
		 * @param p
		 * 
		 */		
		public function set pos(p:Point):void
		{
			_pos.x = p.x;
			_pos.y = p.y;
			x = p.x;
			y = p.y;
		}
		
		/**
		 * 获取坐标点 
		 * @return 
		 * 
		 */		
		public function get pos():Point
		{
			_pos.x = x;
			_pos.y = y;
			return _pos;
		}
		
		override public function set x(v:Number):void
		{
			super.x = v;
			_pos.x = v;
		}
		override public function set y(v:Number):void
		{
			super.y = v;
			_pos.y = v;
		}
		
		/**
		 * 获取本身，Sprite类型返回 
		 * @return 
		 * 
		 */		
		public function get sprite():Sprite
		{
			return this;
		}
		
		/**
		 * 设置方向 
		 * @param dir
		 * 
		 */		
		public function set direction(dir:String):void
		{
			if (dir == null || dir == "")
			{
				return;
			}
			_direction = dir;
		}
		
		/**
		 * 获取方向 
		 * @return 
		 * 
		 */		
		public function get direction():String
		{
			return _direction;
		}
		/**
		 * 销毁 
		 * 
		 */		
		public function destroy():void
		{
			if(_walk)
			{
				_walk.destroy();
			}
			_walk = null;
			
		}
		
	}
}